import request from 'utils/request'

/**
 * 获取所有频道列表
 */
export const getChannels = () => {
  return request({
    method: 'GET',
    url: '/channels',
  })
}

/**
 * 获取文章列表
 */
export const getArticles = (params = {}) => {
  return request({
    method: 'GET',
    url: '/mp/articles',
    params,
  })
}

/**
 * 删除文章
 * @param {*} id 文章id
 */
export const delArticles = (id) => {
  return request({
    method: 'DELETE',
    url: '/mp/articles/' + id,
  })
}

/**
 * 添加文章
 * @param {*} data 请求体，文章的主题内容
 * @param {*} draft 是否草稿，默认值false
 */
export const addArticle = (data, draft = false) => {
  return request({
    method: 'POST',
    url: '/mp/articles',
    params: {
      draft,
    },
    data,
  })
}

/**
 * 根据 id 获取文章详情
 * @param {*} id
 */
export const getArticleById = (id) => {
  return request({
    method: 'GET',
    url: '/mp/articles/' + id,
  })
}

/**
 * 根据 id 修改文章详情
 * @param {*} id
 * @param {*} data
 * @param {*} draft
 */
export const editArticleById = (id, data, draft = false) => {
  return request({
    method: 'PUT',
    url: '/mp/articles/' + id,
    params: {
      draft,
    },
    data,
  })
}
